package com.schoolai.schoolworkflow.task.listeningtraining;

import com.schoolai.feign.local.ai.IFeignPythonService;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.JavaDelegate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Base64;

/**
 * Copyright(C),2019-2025，XX公司
 * FileName:TTS
 * Author:bobby
 * 创建时间：2025/9/28 10:50
 * Description:TTS
 * History:
 * <auth>        <time>       <version>       <desc>
 * 作者          修改时间       版本号         描述
 */
@Slf4j
@Component("TTS")
public class TTS implements JavaDelegate {
    // @Autowired
    // IVoice voice;
    @Autowired
    IFeignPythonService iFeignPythonService;

    @Override
    public void execute(DelegateExecution execution) {
        String text = (String) execution.getVariable("EnglishArticle");
        // 将字符串转换为byte数组
        byte[] bytesToEncode = text.getBytes();
        // 使用Base64编码
        String encodedString = Base64.getEncoder().encodeToString(bytesToEncode);
        // 远程阿里模型
        // voice.genVoiceFile(text);
        // 本地TTS模型
        iFeignPythonService.tts(text.replace("*", ""));
        log.info("TTS任务" + encodedString);
    }
}
